package com.gaussdb.demo;


import com.gaussdb.config.MyConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class GaussWriteDemo {
    public static void main(String[] args) throws SQLException, InterruptedException {

        Connection connection = DriverManager.getConnection(MyConfig.gauss_jdbc, MyConfig.gauss_username, MyConfig.gauss_password);

//        PreparedStatement preparedStatement = connection.prepareStatement("select  * from public.testsource");
        PreparedStatement preparedStatement2 = connection.prepareStatement("insert into public.testsource values (?,?)");
        PreparedStatement preparedStatement3 = connection.prepareStatement("truncate table public.testsource ");

        preparedStatement3.execute();

        for (int i = 1; i < 20000;i++){
            System.out.println("写入tom:"+i);
            preparedStatement2.setInt(1,i);
            preparedStatement2.setString(2,"tom"+i);
            preparedStatement2.execute();
//            Thread.sleep(1000L);
        }



        PreparedStatement preparedStatement4 = connection.prepareStatement("insert into public.test2 values (?,?)");
        PreparedStatement preparedStatement5 = connection.prepareStatement("truncate table public.test2 ");

        preparedStatement5.execute();

        for (int i = 200; i < 20000;i++){
            System.out.println("写入jack:"+i);
            preparedStatement4.setInt(1,i);
            preparedStatement4.setString(2,"jack"+i);
            preparedStatement4.execute();
//            Thread.sleep(1000L);
        }




        preparedStatement2.close();
        preparedStatement3.close();


        preparedStatement4.close();
        preparedStatement5.close();


        connection.close();
    }
}
